<template>
  <page-header-wrapper :title="false">
    <a-card >
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="筛选">
                <a-input v-model="value" placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :md="(!advanced && 8) || 24" :sm="24">
              <span
                class="table-page-search-submitButtons"
                :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
              >
                <a-button type="primary" :loading="loading" @click="handleSearch(queryParam)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table 
        ref="table"
        size="default"
        rowKey="key" 
        :scroll="{ x: 1920 }" 
        :columns="columns" 
        :data-source="loadData">
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="action" slot-scope="text, record">
          <template> <a-tag color="#428bca" @click="handleDetail(record)">详情</a-tag> </template>
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>
  
<script>
import { omit } from 'lodash-es'
import { getOpBusSalesDetailListUsingPOST } from '@/api/api/tongjibaobiao.ts'
export default {
  name: 'ReportMobileDetail',
  data() {
    return {
      mdl: null,
      visible: false,
      activeTabKey: '1',
      confirmLoading: false,
      // 高级搜索 展开/关闭
      advanced: false,
      loading: false,
      pagination:{
        total: 0
      },
      // 查询参数
      queryParam: {
        pageNo:1,
        pageSize:10, 
        date: [this.$route.query.startTime, this.$route.query.endTime],
        queryCondition:'',
        status:''
      },
      optionParam: {
        pageNo: 1,
        pageSize: 999,
        queryCondition: '',
        status: 1,
      },
      // 表头
      columns: [
        {
          title: '订单ID',
          dataIndex: 'orderId',
          width: '100px',
        },
        {
          title: '业务编号',
          dataIndex: 'code',
          width: '100px',
        },
        {
          title: '运营商',
          width: '100px',
          dataIndex: 'operatorName',
        },
        {
          title: '分类',
          dataIndex: 'opBusClsName',
          width: '100px',
        },
        {
          title: '业务',
          dataIndex: 'opBusinessName',
          width: '100px',
        },
        {
          title: '渠道',
          dataIndex: 'opChannelName',
          width: '100px',
        },
        {
          title: '工号',
          dataIndex: 'opEmpNoName',
          width: '100px',
        },
        {
          title: '业务电话',
          dataIndex: 'phone',
          width: '100px',
        },
        {
          title: '身份证号',
          width: '100px',
          dataIndex: 'idCard',
        },
        {
          title: '销售日期',
          width: '144px',
          dataIndex: 'salesDate',
        },
        {
          title: '类型',
          width: '100px',
          dataIndex: 'type',
        },
        {
          title: '酬金',
          width: '100px',
          dataIndex: 'remValue',
        },

        {
          title: '积分',
          width: '100px',
          dataIndex: 'integral',
        },
        {
          title: '成本(元)',
          width: '100px',
          dataIndex: 'cost',
        },
        {
          title: '售价(元)',
          width: '100px',
          dataIndex: 'price',
        },
        {
          width: '150px',
          title: '赠送考核成本(元)',
          dataIndex: 'giftAssCost',
        },
        {
          title: '赠送成本',
          dataIndex: 'giftCost',
          width: '100px',
        },
        {
          title: '毛利',
          width: '100px',
          dataIndex: 'grossProfit',
        },
        {
          width: '100px',
          title: '提成值',
          dataIndex: 'commission',
        },
        {
          width: '100px',
          title: '销售员',
          dataIndex: 'empName',
        },
        {
          width: '100px',
          title: '店面',
          dataIndex: 'storeName',
        },
        {
          width: '100px',
          title: '会员名称',
          dataIndex: 'memName',
        },
        {
          width: '100px',
          title: '会员电话',
          dataIndex: 'memPhone',
        },
        {
          width: '100px',
          title: '会员积分',
          dataIndex: 'memIntegral',
        },
        {
          width: '100px',
          title: '备注',
          dataIndex: 'memo',
        },
        {
          title: '操作',
          dataIndex: 'action',
          fixed:'right',
          width: '180px',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: [],
    }
  },
  mounted() {
    this.handleSearch(this.queryParam)
  },
  methods: {
    handleSearch(val) { 
      this.loading = true
      const params = {
        ...val,
        startTime: this.$route.query.startTime ,
        endTime: this.$route.query.endTime,
      }
      //处理不同类型的请求赋值对应类型 id
      if(this.$route.query.storeId != {}){
        params.storeId = this.$route.query.storeId
      }else if(this.$route.query.empId != {}){
        params.empId = this.$route.query.empId
      }else if(this.$route.query.operatorId != {}){
        params.operatorId = this.$route.query.operatorId
      }else if(this.$route.query.opChannelId != {}){
        params.opChannelId = this.$route.query.opChannelId
      }else if(this.$route.query.opEmpNo != {}){
        params.opEmpNo = this.$route.query.opEmpNo
      }else if(this.$route.query.opBusinessId != {}){
        params.opBusinessId = this.$route.query.opBusinessId
      }else if(this.$route.query.opBusClsId != {}){
        params.opBusClsId = this.$route.query.opBusClsId
      }
      getOpBusSalesDetailListUsingPOST({ ...omit(params, ['date'])})
        .then((res) => {
          this.loadData = res.data.list
          this.loading = false
          this.queryParam.pageNo = this.pagination.current
          this.pagination = { ...this.pagination, total: Number(res.data.total) }
        })
        .catch((error) => {
          this.loading = false
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    handleDetail(record) {
      this.$router.push({ path: `/cashier/profile/index/${record?.orderId}`})
    },
  },
}
</script>